﻿@using SmartStore.Web.Framework
@model SmartStore.DiscountRules.Models.HasAllProductsModel
@{
    Layout = "";
} 
<table class="adminContent">
    <tr class="wide">
        <td class="adminTitle">
            @Html.SmartLabelFor(model => model.Products)
        </td>
        <td class="adminData">
			<div class="discount-rule-wrapper"
				 data-discount-id='@Model.DiscountId'
				 data-requirement-id='@Model.RequirementId'
				 data-action-url='@Url.Action("HasAllProducts")'
				 data-fail-msg=@T("Admin.Promotions.Discounts.Requirements.FailedToSave").JsText
				 data-success-msg=@T("Admin.Promotions.Discounts.Requirements.Saved").JsText>
				<div>
					<div class="input-group">
						@Html.TextBoxFor(model => model.Products, new { data_routeparam = "productIds", @readonly = "readonly" })
						
						<span class="input-group-append">
							<a class="btn btn-secondary" id="reset-productids" title="@T("Admin.Common.Reset")">
								<i class="fa fa-times"></i>
							</a>
						</span>

						<div class="input-group-append">
							@(Html.SmartStore().EntityPicker()
								.For(x => x.Products)
								.HtmlAttribute("class", "btn btn-outline-secondary")
								.DialogTitle(T("Plugins.DiscountRules.HasAllProducts.Fields.Products").Text.EncodeJsString('\'', false))
								.Caption(T("Admin.Common.Search").Text.EncodeJsString('\'', false)))
						</div>
					</div>

					<button type="button" class="btn @(Model.RequirementId == 0 ? "btn-primary btn-block btn-lg" : "btn-warning") btn-save-discount-rule mt-3">
						<i class="fa fa-@(Model.RequirementId == 0 ? "plus" : "check")"></i>
						<span>@T(Model.RequirementId == 0 ? "Common.AddNew" : "Admin.Common.Save")</span>
					</button>
				</div>
			</div>
		</td>
    </tr>
</table>

<script>
	$(function () {
		// reset productids
		$("#reset-productids").on("click", function (e) {
			e.preventDefault();
			$("#@Html.FieldIdFor(model => model.Products)").val("");
		});
	});
</script>